// pages/pay/index.js
import {showToast} from '../../utils/asyncWx'

Page({

  data: {
    address: {},
    cart: [],
    totalPrice: 0,
    totalNum: 0
  },

  onShow() {
    //获取缓存中地址的数据
    const address = wx.getStorageSync('address')
    console.log(address);
    // 1、获取缓存中的数据
    let cart = wx.getStorageSync('cart')
    // 2、筛选数据
    cart = cart.filter(item => item.checked)

    // 计算商品总量 总价
    let totalPrice = 0
    let totalNum = 0
    cart.forEach(item => {
      totalPrice += item.num * item.goods_price
      totalNum += item.num
    });

    // 把数据放回data中
    this.setData({
      address,
      cart,
      totalPrice,
      totalNum
    })
  },

  // 点击支付后
  handleOrderPay() {
    showToast({title: '该功能还在开发中'})
  }
})